<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增菜单')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-type-add">
        <input id="treeId" name="parentId" type="hidden" th:value="${projectType.id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级类型：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" id="treeName" readonly="true"
                           th:value="${projectType.typename}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单类型：</label>
            <div class="col-sm-8">
                <label class="radio-box"> <input type="radio" name="type" value="M"/> 目录 </label>
                <label class="radio-box"> <input type="radio" name="type" value="C"/> 文件名 </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型名：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="typename" id="typename" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderNum" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script>
    var prefix = ctx + "process/projectfiletype";

    $("#form-type-add").validate({
        onkeyup: false,
        rules: {
            menuType: {
                required: true,
            },
            menuName: {
                remote: {
                    url: prefix + "/checkTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "parentId": function () {
                            return $("input[name='parentId']").val();
                        },
                        "typename": function () {
                            return $.common.trim($("#typename").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            orderNum: {
                digits: true
            },
        },
        messages: {
            "typename": {
                remote: "菜单已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-type-add').serialize());
        }
    }


    $("#form-type-add").click(function (event) {
        var obj = event.srcElement || event.target;
        if (!$(obj).is("input[name='icon']")) {
            $(".icon-drop").hide();
        }
    });
    $(".icon-drop").find(".ico-list i").on("click", function () {
        $('#icon').val($(this).attr('class'));
    });


    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>
